<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      #app {
        width: 632px;
        margin: 0 auto;
        text-align: center;
      }

      nav {
        display: inline-block;
        margin: 60px auto 45px;
        background-color: #64b448;
        box-shadow: 0 1px 1px #ccc;
        border-radius: 2px;
      }

      nav a {
        display: inline-block;
        padding: 18px 30px;
        color: #fff !important;
        font-weight: bold;
        font-size: 16px;
        text-decoration: none !important;
        line-height: 1;
        background-color: transparent;
        -webkit-transition: background-color 0.25s;
        -moz-transition: background-color 0.25s;
        transition: background-color 0.25s;
        cursor: pointer;
      }

      b {
        display: inline-block;
        padding: 5px 10px;
        background-color: #64b448;
        border-radius: 2px;
        font-size: 18px;
        color: #fff;
      }

      .show {
        background-color: #e35885;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <nav>
        <a
          v-for="(cnt,i) in contents"
          :key="i"
          @mouseover="fn(i)"
          :class="cnt.type"
        >
          {{cnt.name}}
        </a>
      </nav>
      <p>选择了 <b>{{txt}}</b></p>
    </div>
    <script>
      new Vue({
        el: "#app",
        data: {
          contents: [
            {
              name: "Html",
              type: {
                show: false,
              },
            },
            {
              name: "Css",
              type: {
                show: false,
              },
            },
            {
              name: "Javascript",
              type: {
                show: false,
              },
            },
            {
              name: "Vue.js",
              type: {
                show: false,
              },
            },
          ],
          txt: "Html",
        },
        methods: {
          fn(idx) {
            this.contents.forEach((x) => {
              x.type["show"] = false;
            });
            this.contents[idx]["type"]["show"] = true;
            this.txt = this.contents[idx]["name"];
          },
        },
      });
    </script>
  </body>
</html>
